<template>
  <div class="app-my app-content">
    <div class="app-my-header">
      <div class="app-my-header-info">
        <img src="@/assets/images/default_head_img.png">
        <span>{{ userName }}</span>
      </div>
    </div>
    <div class="app-my-status-bar">
      <div class="app-my-status-bar-item" @click="nav2List('appMyTraining', 1)">
        <div>待培训</div>
        <div style="color: #E68109;">{{ studiesInfo.unTrainedCount || 0 }}</div>
      </div>
      <div class="app-my-status-bar-item" @click="nav2List('appMyTraining', 2)">
        <div>培训中</div>
        <div style="color: #0AB021;">{{ studiesInfo.inTrainingCount || 0 }}</div>
      </div>
      <div class="app-my-status-bar-item" @click="nav2List('appMyTraining', 3)">
        <div>已培训</div>
        <div style="color: #333;">{{ studiesInfo.trainedCount || 0 }}</div>
      </div>
      <div class="app-my-status-bar-item" @click="nav2List('appMyStudy', 2)">
        <div>学习中</div>
        <div style="color: #0AB021;">{{ studiesInfo.learningCount || 0 }}</div>
      </div>
      <div class="app-my-status-bar-item" @click="nav2List('appMyStudy', 3)">
        <div>已学习</div>
        <div style="color: #333;">{{ studiesInfo.learnedCount || 0 }}</div>
      </div>
    </div>
    <van-cell-group inset class="app-my-cell-group">
      <van-cell title="我的收藏" is-link @click="nav2List('appMyCollect')" />
      <van-cell title="我的评论" is-link @click="nav2List('appMyComment')" />
    </van-cell-group>
    <div class="tab-wrap">
      <div class="tabs">
        <div class="item" v-for="(item, i) in tabList" :key="`tab${i}`" :class="{'active': item.active}" @click="chooseTab(item)">
          <x-svg-icon :name="item.active ? item.svg :`${item.svg}line`"></x-svg-icon>
          <div>{{ item.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'appMy',
  data() {
    return {
      userName: sessionStorage.userName,
      studiesInfo: {},
      tabList: [
        {
          name: '课程',
          svg: 'home',
          active: false
        },
        {
          name: '我的',
          svg: 'my',
          active: true
        },
      ],
    };
  },
  methods: {
    async myStudiesInfo () {
      const { data } = await this.Request.myStudiesInfo({ params: { userId: sessionStorage.userId } })
      this.studiesInfo = data;
    },
    nav2List (name, active) {
      this.$router.push({
        name,
        query: { active },
      })
    },
    chooseTab(item){
      if(item.name === '课程') {
        this.$router.push({ path: '/index' })
      }
    },
  },
  mounted () {
    this.myStudiesInfo();
  }
};
</script>

<style lang="scss" scoped>
@import "@/css/variable.scss";
.app-my {
  .app-my-header {
    height: 160px;
    background-image: url('../../../assets/images/appdjt_top_bg.png');
    background-size: 100% 100%;
    position: relative;
    .app-my-header-info {
      position: absolute;
      left: 36px;
      bottom: 30px;
      display: flex;
      align-items: center;
      img {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        border: 2px solid $blue1;
        margin-right: 15px;
      }
      span {
        font-size: 20px;
        font-weight: bold;
        color: $white1;
      }
    }
  }
  .app-my-status-bar {
    height: 73px;
    background: $white1;
    display: flex;
    padding: 17px 19px;
    .app-my-status-bar-item {
      flex: 1;
      border-right: 1px solid $white8;
      &:last-child {
        border-right: none;
      }
      div {
        text-align: center;
        &:nth-child(1) {
          font-size: 0.0933rem;
          color: $white5;
        }
        &:nth-child(2) {
          font-size: 20px;
          font-weight: bold;
        }
      }
    }
  }
  .app-my-cell-group {
    margin-top: 16px;
    .van-cell {
      padding: 13px 16px;
    }
    .van-cell__title {
      font-size: 16px;
    }
  }
}
.tab-wrap{
  display: block;
  position: fixed;
  bottom: 0;
  width: 100%;
  .tabs{
    display: flex;
    height: 2.083rem;
    background-color: #fff;
    .item{
      height: 100%;
      flex: 1;
      align-items: center;
      display: flex;
      flex-flow: column;
      justify-content: center;
      color: #999999;
      .svg-icon{
        font-size: 0.903rem;
        margin-bottom: 0.1rem;
      }
      div{
        font-size: 0.417rem;
        font-weight: 400;
      }
      &.active{
        color: #1D67FF;
      }
    }
  }
}
</style>
